package com.my12306.train.controller;

import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.SeatEntity;
import com.my12306.train.model.vo.PageSeatVo;
import com.my12306.train.service.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 席位信息表
 *
 * @author ËÕÄÁÏ¦
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/seat")
public class SeatController {
    @Autowired
    private SeatService seatService;

    /**
     * 列表
     */
    @PostMapping("/lst")
    public ResponseData list(@RequestBody PageSeatVo pageVo) {
        PageUtils page = seatService.querySeatsByPage(pageVo);
        return ResponseData.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/inf/{seatId}")
    public ResponseData info(@PathVariable("seatId") Long seatId) {
        SeatEntity seat = seatService.getSeatById(seatId);

        return ResponseData.ok().put("seat", seat);
    }

    /**
     * 保存
     */
    @PostMapping("/sv")
    public ResponseData save(@RequestBody SeatEntity seat) {
        return seatService.saveSeat(seat);
    }

    /**
     * 修改
     */
    @PutMapping("/up")
    public ResponseData update(@RequestBody SeatEntity seat) {
        seatService.updateSeatById(seat);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/del")
    public ResponseData delete(@RequestBody List<Long> seatIds) {
        seatService.removeSeatByIds(seatIds);
        return ResponseData.ok();
    }

}
